package com.itboye.shop.presenter;


import com.itboye.shop.bean.GoodsModel;
import com.itboye.shop.bean.ShopCarBean;
import com.itboye.shop.interfaces.IShop;
import com.itboye.shop.net.ICompleteListener;
import com.itboye.shop.net.ResultEntity;
import com.itboye.shop.responsitory.ShopResponsitory;

import java.util.Observer;


/**
 * 商品
 */
public class ShopPresenter extends BasePresenter implements IShop<GoodsModel> {
    //订单创建
    public static final String chuangjian_success = ShopPresenter.class.getName()
            + "_chuangjian_success";
    public static final String chuangjian_fail = ShopPresenter.class.getName()
            + "_chuangjian_fail";
    //商品列表
    public static final String Serach_success = ShopPresenter.class.getName()
            + "_Serach_success";
    public static final String Serach_fail = ShopPresenter.class.getName()
            + "_Serach_fail";
    //商品搜索
    public static final String mall_sousuo_success = ShopPresenter.class.getName()
            + "_mall_sousuo_success";
    public static final String mall_sousuo_fail = ShopPresenter.class.getName()
            + "_mall_sousuo_fail";
    //支付方式
    public static final String pay_fangshi_success = ShopPresenter.class.getName()
            + "_pay_fangshi_success";
    public static final String pay_fangshi_fail = ShopPresenter.class.getName()
            + "_pay_fangshi_fail";
    //商品详情
    public static final String mall_xq_success = ShopPresenter.class.getName()
            + "_mall_xq_success";
    public static final String mall_xq_fail = ShopPresenter.class.getName()
            + "_mall_xq_fail";

    //子类目查询
    public static final String leimu_success = ShopPresenter.class.getName()
            + "_leimu_success";
    public static final String leimu_fail = ShopPresenter.class.getName()
            + "_leimu_fail";
    public static final String query_carsuccess = ShopPresenter.class.getName()
            + "_query_carsuccess";
    public static final String query_carfail = ShopPresenter.class.getName()
            + "_query_carfail";

    //订单分页查询
    public static final String daingdan_query_success = ShopPresenter.class.getName()
            + "_daingdan_query_success";
    public static final String daingdan_query_fail = ShopPresenter.class.getName()
            + "_daingdan_query_fail";
    public static final String deleteShop_success = ShopPresenter.class.getName()
            + "_deleteShop_success";
    public static final String deleteShop_fail = ShopPresenter.class.getName()
            + "_deleteShop_fail";

    public static final String updateShop_success = ShopPresenter.class.getName()
            + "_updateShop_success";
    public static final String updateShop_fail = ShopPresenter.class.getName()
            + "_updateShop_fail";
    public static final String payByWallet_success=ShopPresenter.class.getName()
    + "_payByWallet_success";
    public static final String payByWallet_fail=ShopPresenter.class.getName()
            + "_payByWallet_fail";

    public ShopPresenter(Observer observer) {
        super(observer);
    }

    @Override
    public void shangPinList(String page_index, String page_size, String cate_id, String prop_id, String order, String keyword, String l_price, String r_price) {
        IShop shopsearch = new ShopResponsitory(new ICompleteListener() {
            @Override
            public void success(ResultEntity result) {
                result.setEventTag(Tag_Success);
                result.setEventType(Serach_success);
                setChanged();
                notifyObservers(result);
            }

            @Override
            public void failure(ResultEntity result) {
                result.setEventTag(Tag_Error);
                result.setEventType(Serach_fail);
                setChanged();
                notifyObservers(result);
            }
        });
        shopsearch.shangPinList(page_index, page_size, cate_id, prop_id, order, keyword, l_price, r_price);
    }

    @Override
    public void getMallSouSuo(String keyword) {
        IShop shopsearch = new ShopResponsitory(new ICompleteListener() {
            @Override
            public void success(ResultEntity result) {
                result.setEventTag(Tag_Success);
                result.setEventType(mall_sousuo_success);
                setChanged();
                notifyObservers(result);
            }

            @Override
            public void failure(ResultEntity result) {
                result.setEventTag(Tag_Error);
                result.setEventType(mall_sousuo_fail);
                setChanged();
                notifyObservers(result);
            }
        });
        shopsearch.getMallSouSuo(keyword);
    }

    @Override
    public void payFangShi() {
        IShop shopsearch = new ShopResponsitory(new ICompleteListener() {
            @Override
            public void success(ResultEntity result) {
                result.setEventTag(Tag_Success);
                result.setEventType(pay_fangshi_success);
                setChanged();
                notifyObservers(result);
            }

            @Override
            public void failure(ResultEntity result) {
                result.setEventTag(Tag_Error);
                result.setEventType(pay_fangshi_fail);
                setChanged();
                notifyObservers(result);
            }
        });
        shopsearch.payFangShi();
    }

    @Override
    public void mallXiangQing(String id) {
        IShop shopsearch = new ShopResponsitory(new ICompleteListener() {
            @Override
            public void success(ResultEntity result) {
                result.setEventTag(Tag_Success);
                result.setEventType(mall_xq_success);
                setChanged();
                notifyObservers(result);
            }

            @Override
            public void failure(ResultEntity result) {
                result.setEventTag(Tag_Error);
                result.setEventType(mall_xq_fail);
                setChanged();
                notifyObservers(result);
            }
        });
        shopsearch.mallXiangQing(id);
    }

    @Override
    public void LeiMuQuery(String cate_id) {
        IShop shopsearch = new ShopResponsitory(new ICompleteListener() {
            @Override
            public void success(ResultEntity result) {
                result.setEventTag(Tag_Success);
                result.setEventType(leimu_success);
                setChanged();
                notifyObservers(result);
            }

            @Override
            public void failure(ResultEntity result) {
                result.setEventTag(Tag_Error);
                result.setEventType(leimu_fail);
                setChanged();
                notifyObservers(result);
            }
        });
        shopsearch.LeiMuQuery(cate_id);
    }

    @Override
    public void gouWuChe(String sid,String uid) {
        IShop user = new ShopResponsitory(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(query_carsuccess);
                        ShopPresenter.this.setChanged();
                        ShopPresenter.this.notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Error);
                        result.setEventType(query_carfail);
                        ShopPresenter.this.setChanged();
                        ShopPresenter.this.notifyObservers(result);

                    }
                });
        user.gouWuChe(sid,uid);
    }

    @Override
    public void deleteShop(ShopCarBean shopCarBean) {
        IShop user = new ShopResponsitory(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(deleteShop_success);
                        ShopPresenter.this.setChanged();
                        ShopPresenter.this.notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Error);
                        result.setEventType(deleteShop_fail);
                        ShopPresenter.this.setChanged();
                        ShopPresenter.this.notifyObservers(result);
                    }
                });
        user.deleteShop(shopCarBean);
    }

    @Override
    public void updateShop(ShopCarBean shopCarBean) {
        IShop user = new ShopResponsitory(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(updateShop_success);
                        ShopPresenter.this.setChanged();
                        ShopPresenter.this.notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Error);
                        result.setEventType(updateShop_fail);
                        ShopPresenter.this.setChanged();
                        ShopPresenter.this.notifyObservers(result);
                    }
                });
        user.updateShop(shopCarBean);
    }

    @Override
    public void generateOrder(String s_id, String uid, String ids, String address_id, String del, String note) {
        IShop dingdan = new ShopResponsitory(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(chuangjian_success);
                        ShopPresenter.this.setChanged();
                        ShopPresenter.this.notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Error);
                        result.setEventType(chuangjian_fail);
                        ShopPresenter.this.setChanged();
                        ShopPresenter.this.notifyObservers(result);

                    }
                });
        dingdan.generateOrder(s_id,uid, ids,address_id,del,note);
    }

    @Override
    public void orderQuery(String s_id, String uid, String keyword, String query_status, String page_index, String page_size) {
        IShop dingdan = new ShopResponsitory(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(daingdan_query_success);
                        setChanged();
                        notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Error);
                        result.setEventType(daingdan_query_fail);
                        setChanged();
                        notifyObservers(result);

                    }
                });
        dingdan.orderQuery(s_id,uid, keyword,query_status,page_index,page_size);
    }

    @Override
    public void payByWallet(String uid, String payCode) {
        IShop dingdan = new ShopResponsitory(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(payByWallet_success);
                        setChanged();
                        notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Error);
                        result.setEventType(payByWallet_fail);
                        setChanged();
                        notifyObservers(result);

                    }
                });
        dingdan.payByWallet(uid,payCode);
    }

}
